package org.jsola.contract.helper;

import org.jsola.common.SafeKit;
import org.jsola.contract.dto.PersonSignatureAddDTO;
import org.jsola.contract.dto.PersonSignatureUpdateDTO;
import org.jsola.contract.entity.PersonSignatureDO;
import org.jsola.contract.query.PersonSignatureQuery;
import org.jsola.contract.service.IPersonSignatureService;
import org.jsola.contract.vo.PersonSignatureVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.contract.core.AbstractTest.SITE_ID;



/**
 * 合同个人签名表
 *
 * @author JanusMix
 */
@Component
public class PersonSignatureTestHelper extends BaseTestHelper {
    
    @Autowired
    private IPersonSignatureService personSignatureService;

    /**
     * 生成add测试数据
     * @return PersonSignatureAddDTO
     */
    public PersonSignatureAddDTO getPersonSignatureAddDTO(){
        PersonSignatureAddDTO personSignatureAddDTO = new PersonSignatureAddDTO();
        personSignatureAddDTO.setContractId(SafeKit.getLong(getRandomValue("bigint",11)));
        personSignatureAddDTO.setSeal(getRandomValue("longtext",2147483647));
        personSignatureAddDTO.setUserId(getRandomValue("varchar",32));
        return personSignatureAddDTO;
    }


    /**
     * 生成update测试数据
     * @return PersonSignatureUpdateDTO
     */
    public PersonSignatureUpdateDTO getPersonSignatureUpdateDTO(PersonSignatureVO personSignatureVO){
        return personSignatureService.selectDOById(personSignatureVO.getId(), SITE_ID).to(PersonSignatureUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return PersonSignatureQuery
     */
    public PersonSignatureQuery getPersonSignatureQuery() {
        PersonSignatureQuery personSignatureQuery = new PersonSignatureQuery();
        List<PersonSignatureDO> personSignatureDOList = personSignatureService.list(new PersonSignatureDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(personSignatureDOList)) {
            PersonSignatureDO personSignatureDO = personSignatureDOList.get(0);
            personSignatureQuery = personSignatureDO.to(PersonSignatureQuery.class);
        }
        return personSignatureQuery;
    }

    /**
     * 保存示例
     * @return PersonSignatureVO
     */
    public PersonSignatureVO savePersonSignatureExample(){
        PersonSignatureAddDTO addDTO = this.getPersonSignatureAddDTO();
        PersonSignatureVO personSignatureVO = personSignatureService.save(addDTO,buildTokenUser());
        return personSignatureVO;
    }


}

